// import QtQuick 1.0 // to target S60 5th Edition or Maemo 5
import QtQuick 1.1
import QtMultimediaKit 1.1
import com.nokia.symbian 1.1
import Qt.labs.components 1.1
import "EasyModeProcess.js" as EasyModeProcess

Item {
    id: start
    signal clickedHideStart
    property bool flagSound: false
    property int flagStartMenuHide: 1

    Audio{
        id: audioStart
        source: "Audio/playgame.wav"
        autoLoad: true
        volume: 0.5
    }
    Audio{
        id:right
        source: "Audio/right.mp3"
        volume: 0.7
    }

    Timer{
        id: timerStopStart
        interval: 40000; running: false; repeat: true
        onTriggered: EasyModeProcess.restartMusic()
    }

    /// highScore
    Rectangle{
        id: highScoreWindow
        anchors.fill: parent
        opacity: 0

        property int flagHideHighScore: 1
        onStateChanged: EasyModeProcess.dataList()


        Image {
            id: backgroundHighScore
            source: "Image/background/portraitplay.jpg"
        }

        Text {
            id: textHighScore
            color: "#f18a14"
            text: qsTr("HighScore")
            font.bold: true
            x: (parent.width - 50)/4.0
            y: 40
            font.family: "Helvetica"
            font.pointSize: 18
        }

        Component {
            id: listDelegate
            Item {
                    id: itemlist
                    width: 250; height: 120
                    x: 80
                    y: 150
                    Row {

                         Column {
                             width: 200
                             x: 80
                             y: 150
                             Text { text: 'Name: ' + name ;color: "#f48314"; font.bold: true;font.family: "Helvetica";font.pointSize: 9}

                             Text { text: 'Score: ' + score ;color: "#f48314"; font.bold: true;font.family: "Helvetica";font.pointSize: 9; }

                             Text { text: 'Mode: ' + mode ;color: "#f48314"; font.bold: true;font.family: "Helvetica";font.pointSize: 9; }
                            }
                    }
                }
        }

        Component {
            id: listDelegateLandscape
            Item {
                    id: itemlistlandscape
                    width: 250; height: 40
                    x: 130
                    y: 110
                    Row {
                         y: 110
                         Text { text: 'Name: ' + name + '  ';color: "#f48314"; font.bold: true;font.family: "Helvetica";font.pointSize: 9}

                         Text { text: 'Score: ' + score + '  ';color: "#f48314"; font.bold: true;font.family: "Helvetica";font.pointSize: 9 }

                         Text { text: 'Mode: ' + mode ;color: "#f48314"; font.bold: true;font.family: "Helvetica";font.pointSize: 9 }

                    }
                }
        }
        ListModel {
                 id: listModel

                 ListElement {
                     name: "Apple"; score:"100"; mode:"easy"
                 }
         }

        ListView {
              id: listView
              x: 40
              y: 0
              anchors.fill: parent; anchors.margins: 5
              model: listModel
              delegate: listDelegate
              focus: true
        }

        Image {
            id: backMyButtonHighScore

            anchors {
                left: parent.left
                bottom: parent.bottom
            }

            source: "Image/Button/back.png"

            MouseArea {
                anchors.fill: parent
                onPressed: parent.scale = 0.9
                onReleased: parent.scale = 1.0
                onClicked: {
                    highScoreWindow.flagHideHighScore = 1
                    highScoreWindow.state ="hide";
                    //MenuProcess.showMenu();
                    EasyModeProcess.showMenuStart();
                }
            }
        }

        states: [
            State {
                name: "hide"
                PropertyChanges {
                    target: highScoreWindow
                    opacity: 0
                }
            },
            State{
                name:"highScoreLandscape"
                when:((highScoreWindow.width > highScoreWindow.height)&&(highScoreWindow.flagHideHighScore == 0))
                PropertyChanges {
                    target: backgroundHighScore
                    source: "Image/background/landscapeplay.jpg"
                }
                PropertyChanges {
                    target: highScoreWindow
                    opacity: 100
                }
                PropertyChanges {
                    target: textHighScore
                    x: (parent.width)/3.0
                    y: 20
                }
                PropertyChanges {
                    target: listView
                    delegate:listDelegateLandscape
                }

            },
            State{
                name:"highScorePortrait"
                when:((highScoreWindow.width < highScoreWindow.height)&&(highScoreWindow.flagHideHighScore == 0))
                PropertyChanges {
                    target: backgroundHighScore
                    source: "Image/background/portraitplay.jpg"
                }
                PropertyChanges {
                    target: highScoreWindow
                    opacity: 100
                }


            }
        ]
    }

    //easymodeWindow
    Rectangle{
        id: easymodeWindow
        property int flagHideEasymode: 1
        anchors.fill: parent
        opacity: 0

        Image {
            id: backgroundEasymode
            source: "Image/background/portraitplay.jpg"
        }

        Image {
            id: imageQuestion

            x: 40
            y: 55

        }

        Timer {
                id: timer
                interval: 1000; running: false; repeat: true
                onTriggered: EasyModeProcess.nextTime()
            }

        CheckableGroup { id: group }
        Column {
             id: col
               x:30
               y:370
             spacing: platformStyle.paddingMedium
             Row{
                 RadioButton {
                     id: button1
                     platformExclusiveGroup: group

                 }
                 Image{
                     id: imageA1

                     MouseArea{
                         anchors.fill: parent
                         onClicked: button1.checked = "true"
                     }
                 }

                 RadioButton {
                     id: button2
                     platformExclusiveGroup: group
                 }
                 Image{
                     id: imageA2

                     MouseArea{
                         anchors.fill: parent
                         onClicked: button2.checked = "true"
                     }
                 }
            }

             Row{
                 RadioButton {
                     id: button3
                     platformExclusiveGroup: group

                 }
                 Image{
                     id: imageA3

                     MouseArea{
                         anchors.fill: parent
                         onClicked: button3.checked = "true"
                     }
                 }
                 RadioButton {
                     id: button4
                     platformExclusiveGroup: group
                     checked: true

                 }
                 Image{
                     id: imageA4

                     MouseArea{
                         anchors.fill: parent
                         onClicked: button4.checked = "true"
                     }
                 }
             }

         }
        Text{
             id: scoreText
             x: 20
             y: 5
             color: "#f18a14"
             text: qsTr("Score: 0")
             font.family: "Helvetica"
             font.pointSize: 10
         }

        Text{
             id: timerText
             x:210
             y: 5
             color: "#f18a14"
             text: qsTr("Time: 0")
             font.family: "Helvetica"
             font.pointSize: 10
         }

        Button{
             id: buttonNext
             y: parent.height -90
             text: qsTr("Next")
             onClicked: {
                 EasyModeProcess.nextPage()
             }
         }


         states: [
             State {
                 name: "easymodeLandscape"
                 when:((easymodeWindow.width > easymodeWindow.height)&&(easymodeWindow.flagHideEasymode == 0))
                 PropertyChanges {
                     target: backgroundEasymode
                     source: "Image/background/landscapeplay.jpg"
                 }
                 PropertyChanges {
                     target: col
                     x:350
                     y:60
                 }
                 PropertyChanges {
                     target: buttonNext
                     x: 350
                 }
                 PropertyChanges {
                     target: easymodeWindow
                     opacity: 100
                 }



             },
             State{
                 name:"easymodePortrait"
                 when:((easymodeWindow.width < easymodeWindow.height)&&(easymodeWindow.flagHideEasymode == 0))
                 PropertyChanges {
                     target: backgroundEasymode
                     source: "Image/background/portraitplay.jpg"
                 }
                 PropertyChanges {
                     target: easymodeWindow
                     opacity: 100
                 }


             },
             State {
                 name: "easymodeHide"
                 PropertyChanges {
                     target: easymodeWindow
                     opacity: 0
                 }
             }

         ]

    }

    //easymodeConclusion
    Rectangle{
        id: easymodeConclusion
        property int flagHideEasymodeConclusion: 1
        anchors.fill: parent
        opacity: 0
        Image {
            id: backgroundEasymodeConclusion
            source: "Image/background/portraitplay.jpg"
        }
        Text{
            id: scoreTextEasyMode
            color: "#f18a14"
            x: parent.width/4.0
            y: 20
            font.family: "Helvetica"
            font.pointSize: 14
        }

        Button{
            id: buttonNextLevel
            x: 20
            y: parent.height -140
            text: qsTr("NextLevel")
            onClicked: {
                EasyModeProcess.nextLevel()
            }
        }

        Button{
            id: buttonEasyModeReturnMenu
            x: 200
            y: parent.height -140
            text: qsTr("Menu")
            onClicked: {

                EasyModeProcess.saveState();
                clickedHideStart();
            }
        }

        states: [
            State {
                name: "easymodeConclusionLandscape"
                when:((easymodeConclusion.width > easymodeConclusion.height)&&(easymodeConclusion.flagHideEasymodeConclusion == 0))
                PropertyChanges {
                    target: backgroundEasymodeConclusion
                    source: "Image/background/landscapeplay.jpg"
                }

                PropertyChanges {
                    target: easymodeConclusion
                    opacity: 100
                }


            },
            State{
                name:"easymodeConclusionPortrait"
                when:((easymodeConclusion.width < easymodeConclusion.height)&&(easymodeConclusion.flagHideEasymodeConclusion == 0))
                PropertyChanges {
                    target: backgroundEasymodeConclusion
                    source: "Image/background/portraitplay.jpg"
                }
                PropertyChanges {
                    target: easymodeConclusion
                    opacity: 100
                }

            },
            State {
                name: "easymodeConclusionHide"
                PropertyChanges {
                    target: easymodeConclusion
                    opacity: 0
                }
            }

        ]
    }

    //userNameWindow
    Rectangle{
         id: userNameWindow
         property int flagHideUserName: 1
         anchors.fill: parent
         opacity: 0

         Image {
             id: backgroundUserName
             source: "Image/background/usernameportrait.jpg"
         }

         Text{
             id:textus
             color: "#ff4a14"
             text: qsTr("User name")
             x: parent.width/4.0
             y: 100
             font.family: "Helvetica"
             font.pointSize: 14
         }

         Rectangle{
             color: "#f18a14"
             x: 20
             y: 200
             width: 300
             id: textArea

                 height: textEdit.height + textEdit.font.pointSize

                 border.width: 3
                 border.color: "lightgrey"
                 radius: textEdit.font.pointSize
                 smooth: true

                 TextEdit {
                     id: textEdit
                     anchors.centerIn: parent
                     width: parent.width - (2 * font.pointSize)
                     font.pointSize: 17
                     color: "black"
                     text:""

                 }
         }

         Image{
           id: buttonSaveName
           x:120
           y: parent.height - 180
           source: "Image/Button/ok.png"
           MouseArea{
               anchors.fill: parent
               onPressed: parent.scale = 0.9
               onReleased: parent.scale = 1.0
               onClicked: {
                   EasyModeProcess.assignName(textEdit.text);
                   userNameWindow.flagHideUserName = 1;
                   userNameWindow.state ="userNameWindowHide"
                   startWindow.flagHideStart = 0;
                   if(userNameWindow.width < userNameWindow.height)
                       startWindow.state = "startWindowPortrait"
                   else
                       startWindow.state ="startWindowLandscape"
               }
           }
         }


         states: [
             State {
                 name: "userNameWindowLandscape"
                 when:((userNameWindow.width > userNameWindow.height)&&(userNameWindow.flagHideUserName == 0))
                 PropertyChanges {
                     target: backgroundUserName
                     source: "Image/background/username.jpg"
                 }

                 PropertyChanges {
                     target: userNameWindow
                     opacity: 100
                 }

                 PropertyChanges {
                     target: textus
                     x: 90
                     y: 40
                 }
                 PropertyChanges {
                     target: textArea
                     x: 40
                     y: 120
                 }
                 PropertyChanges {
                     target: buttonSaveName

                     y: 240
                 }


             },
             State{
                 name:"userNameWindowPortrait"
                 when:((userNameWindow.width < userNameWindow.height)&&(userNameWindow.flagHideUserName == 0))
                 PropertyChanges {
                     target: backgroundUserName
                     source: "Image/background/usernameportrait.jpg"
                 }
                 PropertyChanges {
                     target: userNameWindow
                     opacity: 100
                 }

             },
             State {
                 name: "userNameWindowHide"
                 PropertyChanges {
                     target: userNameWindow
                     opacity: 0
                 }
             }

         ]
     }

    //startWindow
    Rectangle{
    id: startWindow
    property int flagHideStart: 1
    anchors.fill: parent
    opacity: 0


    Image {
      id: backgroundStart
      source: "Image/background/emhportrait.jpg"
    }

    Image{
      id: buttonEasy
      x: 110
      y: parent.height -200
      source: "Image/Button/easy.png"
      MouseArea{
          anchors.fill: parent
          onPressed: parent.scale = 0.9
          onReleased: parent.scale = 1.0
          onClicked: {
              EasyModeProcess.choiceMap(1);
          }
      }
    }

    Image{
      id: buttonMedium
      x: 110
      y: parent.height -330
      source: "Image/Button/medium.png"
      MouseArea{
          anchors.fill: parent
          onPressed: parent.scale = 0.9
          onReleased: parent.scale = 1.0
          onClicked: {
              EasyModeProcess.choiceMap(2);
          }
      }
    }

    Image{
      id: buttonHard
      x:110
      y: parent.height -470
      source: "Image/Button/hard.png"
      MouseArea{
          anchors.fill: parent
          onPressed: parent.scale = 0.9
          onReleased: parent.scale = 1.0
          onClicked: {
              EasyModeProcess.choiceMap(3);
          }
      }
    }

    states: [
      State {
          name: "startWindowHide"
          PropertyChanges {
              target: startWindow
              opacity: 0
          }
      },
      State{
          name:"startWindowLandscape"
          when:((parent.width > parent.height)&&(startWindow.flagHideStart == 0))
          PropertyChanges {
              target: backgroundStart
              source: "Image/background/emhlandscape.jpg"
          }
          PropertyChanges {
              target:buttonEasy
              x: (parent.width - 320)/2.0
              y: parent.height -140
          }
          PropertyChanges {
              target:buttonMedium
              x: (parent.width + 40)/2.0
              y: parent.height -200
          }
          PropertyChanges {
              target:buttonHard
              x: (parent.width - 200)/2.0
              y: parent.height - 340
          }

          PropertyChanges {
              target: startWindow
              opacity:100
          }

      },
      State{
          name:"startWindowPortrait"
          when:((parent.width < parent.height)&&(startWindow.flagHideStart == 0))
          PropertyChanges {
              target: backgroundStart
              source: "Image/background/emhportrait.jpg"
          }
          PropertyChanges {
              target: startWindow
              opacity:100
          }
      }
    ]
    }

    //startMenuWindow
    Rectangle{
        id: startMenuWindow

        anchors.fill: parent
        opacity: 0


        Image {
            id: backgroundStartMenu
            source: "Image/background/portraitMenuStart.jpg"
        }

        Image{
          id: buttonHighscore
          x:140
          y: parent.height - 500
          source: "Image/Button/highscore.png"
          MouseArea{
              anchors.fill: parent
              onPressed: parent.scale = 0.9
              onReleased: parent.scale = 1.0
              onClicked: {
                  EasyModeProcess.hideMenuStart()

                  highScoreWindow.flagHideHighScore = 0;
                  if(startMenuWindow.width < startMenuWindow.height)
                      highScoreWindow.state = "highScorePortrait"
                  else
                      highScoreWindow.state ="highScoreLandscape"
              }
          }
        }

        Image{
          id: buttonNewGame
          x:140
          y: parent.height - 320
          source: "Image/Button/newgame.png"
          MouseArea{
              anchors.fill: parent
              onPressed: parent.scale = 0.9
              onReleased: parent.scale = 1.0
              onClicked: {
                  EasyModeProcess.hideMenuStart()

                  userNameWindow.flagHideUserName = 0;
                  if(startMenuWindow.width < startMenuWindow.height)
                      userNameWindow.state = "userNameWindowPortrait"
                  else
                      userNameWindow.state ="userNameWindowLandscape"
                  EasyModeProcess.addHighScore();
              }
          }
        }

        Image{
          id: buttonContinue
          x:60
          y: parent.height - 190
          source: "Image/Button/continue.png"
          MouseArea{
              anchors.fill: parent
              onPressed: parent.scale = 0.9
              onReleased: parent.scale = 1.0
              onClicked: {
                  var ch = EasyModeProcess.checkContinue();
                  if(ch !== 0){
                      EasyModeProcess.hideMenuStart()

                      EasyModeProcess.showEasyMode();
                      EasyModeProcess.continueGame();
                  }
              }
          }
        }

        states: [
            //startMenuWindowHide
            State {
                name: "startMenuWindowHide"

                PropertyChanges {
                    target: startMenuWindow
                    opacity: 0
                }
                PropertyChanges {
                    target: audioStart
                    playing:true
                }
                PropertyChanges {
                    target: timerStopStart
                    running: true

                }
            },
            //startMenuWindowHideNoSound
            State {
                name: "startMenuWindowHideNoSound"

                PropertyChanges {
                    target: startMenuWindow
                    opacity: 0
                }
                PropertyChanges {
                    target: audioStart
                    playing: false
                }
                PropertyChanges {
                    target: timerStopStart
                    running: false
                }
            },
            //startMenuWindowLandscapeNoSound
            State{
                name:"startMenuWindowLandscapeNoSound"
                when:((parent.width > parent.height)&&(flagStartMenuHide == 0)&&(flagSound == false))
                PropertyChanges {
                    target: backgroundStartMenu
                    source: "Image/background/landscapeMenuStart.jpg"
                }
                PropertyChanges {
                    target:buttonHighscore
                    x: (parent.width - 150)/2.0
                    y: parent.height -276
                }
                PropertyChanges {
                    target:buttonNewGame
                    x: (parent.width - 40)/2.0
                    y: parent.height -150
                }
                PropertyChanges {
                    target:buttonContinue
                    x: (parent.width - 350)/2.0
                    y: parent.height -100
                }

                PropertyChanges {
                    target: startMenuWindow
                    opacity:100
                }
                PropertyChanges {
                    target: audioStart
                    playing: false
                }
                PropertyChanges {
                    target: timerStopStart
                    running: false
                }
            },
            //startMenuWindowLandscape
            State{
                name:"startMenuWindowLandscape"
                when:((parent.width > parent.height)&&(flagStartMenuHide == 0)&&(flagSound == true))
                PropertyChanges {
                    target: backgroundStartMenu
                    source: "Image/background/landscapeMenuStart.jpg"
                }
                PropertyChanges {
                    target:buttonHighscore
                    x: (parent.width - 150)/2.0
                    y: parent.height -276
                }
                PropertyChanges {
                    target:buttonNewGame
                    x: (parent.width - 40)/2.0
                    y: parent.height -150
                }
                PropertyChanges {
                    target:buttonContinue
                    x: (parent.width - 350)/2.0
                    y: parent.height -100
                }


                PropertyChanges {
                    target: startMenuWindow
                    opacity:100
                }
                PropertyChanges {
                    target: audioStart
                    playing:true
                }
                PropertyChanges {
                    target: timerStopStart
                    running: true

                }
            },
            //startMenuWindowPortraitNoSound
            State{
                name:"startMenuWindowPortraitNoSound"
                when:((parent.width < parent.height)&&(flagStartMenuHide == 0)&&(flagSound == false))
                PropertyChanges {
                    target: backgroundStartMenu
                    source: "Image/background/portraitMenuStart.jpg"
                }
                PropertyChanges {
                    target: startMenuWindow
                    opacity:100
                }
                PropertyChanges {
                    target: audioStart
                    playing: false
                }
                PropertyChanges {
                    target: timerStopStart
                    running: false
                }
            },
            //startMenuWindowPortrait
            State{
                name:"startMenuWindowPortrait"
                when:((parent.width < parent.height)&&(flagStartMenuHide == 0)&&(flagSound == true))
                PropertyChanges {
                    target: audioStart
                    playing:true
                }
                PropertyChanges {
                    target: backgroundStartMenu
                   source: "Image/background/portraitMenuStart.jpg"
                }

                PropertyChanges {
                    target: startMenuWindow
                    opacity:100
                }

                PropertyChanges {
                    target: timerStopStart
                    running: true

                }
            }

        ]
    }

}
